package com.woorigil.social.domain.deal;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.woorigil.social.domain.SqlMapDaoSupport;

@Repository
public class RecentQueryDao extends SqlMapDaoSupport<RecentQuery, String> {
	public static final String NAMESPACE = "RecentQuery";

	@Override
	public String getNamespace() {
		return NAMESPACE;
	}
	
	public int deleteBySidAndQuery(String sid, String query) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("sid", sid);
		params.put("query", query);
		return getSqlMapClientTemplate().update(getStatementName(NAMESPACE, "deleteBySidAndQuery"), params);
	}

	public int updateByQuery(RecentQuery recentQuery) {
		return getSqlMapClientTemplate().update(getStatementName(NAMESPACE, "updateByQuery"), recentQuery);
	}
	
	public RecentQuery selectBySidAndQuery(String sid, String query) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("sid", sid);
		params.put("query", query);
		return (RecentQuery)getSqlMapClientTemplate().queryForObject(getStatementName(NAMESPACE, "selectBySidAndQuery"), params);
	}

	@SuppressWarnings("unchecked")
	public List<RecentQuery> search(String sid) {
		return getSqlMapClientTemplate().queryForList(getStatementName(NAMESPACE, "search"), sid);
	}
}